package com.fsl.amsmanagercenter.controller;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.annotation.JsonAppend;
import com.fsl.amsmanagercenter.fegin.DingFeginClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@RestController
public class AmsMangerController {

    @Value("${server.port}")
    String port;

    private static final String DING_SERVICE_NAME = "ding-manager-service";


    @Autowired
    RestTemplate restTemplate;

    @Autowired
    DingFeginClient feginClient;

    /**
     * get请求
     * @return
     */
    @ResponseBody
    @RequestMapping("/getAmsInfo")
    public String getAmsInfo(){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("name","king james");
        map.put("age",33);
        map.put("team","Cleveland Cavaliers");
        map.put("service","ams");
        map.put("port",port);
        return JSON.toJSONString(map);
    }


    /**
     * get请求
     * @return
     */
    @ResponseBody
    @RequestMapping("/getInfoFromDingServiceByRest")
    public String getInfoFromDingServiceByRest(){
        Object forObject = restTemplate.getForObject("http://" + DING_SERVICE_NAME + "/getDingInfo", Object.class);
        return JSON.toJSONString(forObject);
    }


    /**
     * get请求
     * @return
     */
    @ResponseBody
    @RequestMapping("/getInfoFromDingServiceByFegin")
    public String getInfoFromDingServiceByFegin(){
        return feginClient.getDingInfo();
    }


}
